package com.csdj.questions.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csdj.questions.entity.AttentionQuestion;
import com.csdj.questions.entity.TQuestion;
import com.csdj.questions.entity.TQuestionTUsers;
import com.csdj.questions.mapper.TQuestionMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 问题表 服务实现类
 * </p>
 *
 * @author 刘宇
 * @since 2022-03-02
 */
@Service
public class TQuestionService extends ServiceImpl<TQuestionMapper, TQuestion> implements ITQuestionService {

    @Resource
    private TQuestionMapper tQuestionMapper;
    /**
     * 连表查询 查user用户表和TQuestion评论表
     * @return
     */
    @Override
    public List<TQuestionTUsers> selectTQuestionAll() {
        List<TQuestionTUsers>list = tQuestionMapper.selectTQuestionAll();
        return list;
    }
    /**
     * 连表查询 查user用户表和TQuestion评论表 并按照时间降序来排列
     * @return
     */

    @Override
    public List<TQuestionTUsers> selectTQUTimeDesc() {
        List<TQuestionTUsers>list = tQuestionMapper.selectTQUTimeDesc();
        return list;
    }

    /**
     * 连表查询 查user用户表和TQuestion评论表 并按照访问人数降序来排列
     * @return
     */
    @Override
    public List<TQuestionTUsers> selectTQUBrowseNumbDesc() {
        List<TQuestionTUsers>list = tQuestionMapper.selectTQUBrowseNumbDesc();
        return list;
    }

    /**
     * 发布一个问题
     * @param tQuestion 实体类
     * @return
     */
    @Override
    public int insertQuestion(TQuestion tQuestion) {
        return tQuestionMapper.insert(tQuestion);
    }

    @Override
    public List<TQuestionTUsers> selQuestion(String questionId){

            List<TQuestionTUsers> tQuestionTUsersList=tQuestionMapper.selQuestion(questionId);
            return tQuestionTUsersList;
    }

    /**
     * 多表查询，根据用户id查问题表的name
     * @return
     */
    @Override
    public List<AttentionQuestion> selectName(int uid) {
        List<AttentionQuestion> list = tQuestionMapper.selectName(uid);
        return list;
    }
}
